package com.markus.code.exam.tongcheng58;

import java.util.Arrays;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/14 20:55
 * todo:
 */
public class Main2 {
    /**
     *
     * @param nums int整型一维数组
     * @return int整型
     */
    public int firstMissingPositive (int[] nums) {
        // write code here
        if (nums.length == 0){
            return 1;
        }
        int index = 0;
        Arrays.sort(nums);
        while(index<nums.length){
            if (nums[index] < nums.length && nums[index] >=1){
                int tmp = nums[nums[index]-1];
                nums[nums[index]-1] = nums[index];
                nums[index] = tmp;
            }
            index++;
        }
        for (index=0;index<nums.length;index++){
            if (nums[index] != index+1){
                return index+1;
            }
        }
        return nums.length+1;
    }
}
